package com.woniuxy.repay.service.impl;

import com.woniuxy.entity.RepaymentRegistration;
import com.woniuxy.repay.entity.PageBean;
import com.woniuxy.repay.mapper.RepaymentRegistrationMapper;
import com.woniuxy.repay.service.RepaymentRegistrationService;
import com.woniuxy.repay.tools.ServiceTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shichen
 * @create 2021-11-24-9:43
 * @description
 */
@Service
public class RepaymentRegistrationServiceImpl implements RepaymentRegistrationService {
    @Resource
    RepaymentRegistrationMapper repaymentRegistrationMapper;

    @Override
    public PageBean selectByCondition(RepaymentRegistration repaymentRegistration, Integer pageIndex) {
        List<RepaymentRegistration> repaymentRegistrations = repaymentRegistrationMapper.selectByCondition(repaymentRegistration);
        List dataList = ServiceTool.createDataList(repaymentRegistrations, pageIndex);

        return new PageBean<>(repaymentRegistrations.size(), 5, pageIndex, dataList);

    }

    @Override
    public void updateByCondition(RepaymentRegistration repaymentRegistration) {
        // 判断是否符合条件
        if (repaymentRegistration.getId()!= 0){
            repaymentRegistrationMapper.updateByCondition(repaymentRegistration);
        }

    }

    @Override
    public void insert(RepaymentRegistration repaymentRegistration) {
        repaymentRegistrationMapper.insertByCondition(repaymentRegistration);
    }
}
